<?php
//    require_once('class.BasicAnalyzer.php');
    /**
    * 用于提取 sina 网站的视频
    *
    */
    class SinaAnalyzer extends BasicAnalyzer implements Analyzer
    {
        public $features = array("url" => "/http:\/\/you.video.sina.com.cn\/b\/.*\.html/i");

        public function analyze($content, $url)
        {
            preg_match("/http:\/\/you.video.sina.com.cn\/b\/([0-9]+)-([0-9]+)\.html/", $url, $matches);
            $vid = $matches[1];
            preg_match("/_S_PID_=\"([0-9]+)\"/", $content, $matches);
            $pid = $matches[1];
            $tid = rand(0, 9);
            $ran = "0." . rand(10000,99999) . rand(10000,99999) .rand(10000,99999) .rand(10000,99999);
            $xmlurl = "http://v.iask.com/v_play.php?vid=$vid&pid=$pid&tid=$tid&ran=$ran";
            
            $xml = $this->getPage($xmlurl);
            preg_match("/<url><!\[CDATA\[(.+)\]\]>/", $xml, $matches);
            $vurl  = $matches[1];
            preg_match("/<vname><!\[CDATA\[(.+)\]\]>/", $xml, $matches);
            $title = $matches[1];
            $descr = $title;
            $tags  = array();
            $tags[] = "sr_sina";
            $referer = $url;
            $ext="";
            $category ="";
            preg_match("/<span class=\"fright\">[^0-9]+([^<]+)<\/span>/", $content, $matches);
            $pub_date = $matches[1];
            preg_match("/<div class=\"tit\"><strong>(.*)<\/strong>/", $content, $matches);
            $author = iconv("gbk//ignore","utf-8//ignore", $matches[1]);


                
            //===================================
            $rv = array(
                array(
                    "url" => $vurl, 
                    "title" => $title,
                    "descr" => $descr,
                    "referer" => $referer,
                    "tags" => $tags, 
                    "category" => $category,
                    "ext" => $ext,
                    "pub_date" => $pub_date,
                    "author" => $author
                    )
                );

            
            //===================================

            return $rv;
        }
    }

?>
